<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/9/5
 * Time: 17:53
 */

namespace app\api\controller;


use addons\third\library\Service;
use app\common\controller\Api;

class Wechat extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function wechat()
    {
        $code = $this->request->get('code');//微信code
        $icode = $this->request->get('icode');//推广icode
        $state = $this->request->get('state');//微信state
        //获取用户信息
        $app = new \addons\third\library\Wechat();
        $userinfo = $app->getUserInfo(['code'=>$code,'state'=>$state]);
        //$this->auth->register('');
        $res = Service::connect('wechat',$userinfo,['code'=>$icode]);
        if ($res) {
            $data = ['userinfo' => $this->auth->getUserinfo()];
            $this->success(__('Sign up successful'), $data);
        } else {
            $this->error($this->auth->getError());
        }
    }
}